#include <iostream>
#include <cstring>
using namespace std;
struct node{
    int x;
    int y;
}point[150];
double mult(node a, node b, node c)
{
    return (a.x-c.x)*(b.y-c.y)-(b.x-c.x)*(a.y-c.y);
}

//aa, bb为一条线段两端点 cc, dd为另一条线段的两端点 相交返回true, 不相交返回false
bool intersect(node aa, node bb, node cc, node dd)
{
    if ( max(aa.x, bb.x)<min(cc.x, dd.x) )
    {
        return false;
    }
    if ( max(aa.y, bb.y)<min(cc.y, dd.y) )
    {
        return false;
    }
    if ( max(cc.x, dd.x)<min(aa.x, bb.x) )
    {
        return false;
    }
    if ( max(cc.y, dd.y)<min(aa.y, bb.y) )
    {
        return false;
    }
    if ( mult(cc, bb, aa)*mult(bb, dd, aa)<0 )
    {
        return false;
    }
    if ( mult(aa, dd, cc)*mult(dd, bb, cc)<0 )
    {
        return false;
    }
    return true;
}




int main(){
    long long n;
    while (cin >> n){
        for (int i = 0; i < n; ++i) {
            int m;
            cin>>m;
            for (int i = 0; i < m; i++) {
                cin >> point[i].x >> point[i].y;
            }
            int ans = 0;
            for (int i = 0; i < m; i++){
                for (int j = i+1; j < m; j++) {
                    for (int k = j+1; k < m; k++) {
                        for (int l = k+1; l < m; l++) {
                            if(intersect(point[i],point[j],point[k],point[l])){
                                ans++;
                            }
                        }
                    }
                }
            }
            cout << ans << endl;
        }
    }

    return 0;
}
